<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>低代码平台 SSO Demo</title>
  <script src="js/axios.min.js"></script>
  <script src="js/md5.js"></script>
  <script>
    /**
     * 低代码平台配置的业务地址
     * */
    let bizUrl = 'http://localhost:3000/home?1=1';
    bizUrl = 'http://localhost:3000/model/jzblxw?p_layout=appmain';
    // bizUrl = 'http://test.5ihuijia.com/model/jzblxw?p_layout=appmain';
    // bizUrl = 'http://192.168.5.4:3000/model/jzblxw?p_layout=appmain';

    let bizUrl2 = '/model/jzyzblxw';
    bizUrl2 = '/model/jzyzblxw?p_layout=appmain';
    // end
    function goto(){
      var myiframe = document.getElementById("myiframe");
      myiframe.contentWindow.postMessage({url:bizUrl2,origin:window.location.origin},"*")
    }
    function login() {
      
      /***
       * 单点登录url
       * */
      let loginUrl = 'http://test.5ihuijia.com/api/oauth/Login';
      // loginUrl='http://lc.hztianque.com/api/oauth/Login' ;
      loginUrl='http://localhost:3000/dev/api/oauth/Login' ;
      // loginUrl = 'http://192.168.5.3:30000/api/oauth/Login';
      // loginUrl = 'http://192.168.5.4:8880/api/oauth/Login';
      // end

      /**
       * 参数说明：
       * 以下参数不变
       * */
      let grant_type = 'password';
      let origin = 'password  ';
      let code = '';
      let client_id = 'admin';
      let client_secret = '123456';
      let scope = 'all';
      // end 结束参数说明

//LoginForm(account=hnadmin, password=adcf5772c87af0314b2e9bd552a87b74, timestamp=null, code=)
      const params = new URLSearchParams();
      params.append('grant_type', 'password');
      params.append('origin', origin);
      params.append('grant_type', 'password');
      params.append('code', code);
      params.append('client_id', client_id);
      params.append('client_secret', client_secret);
      params.append('scope', scope);

      params.append('account', document.getElementById('username').value);
      params.append('password', hex_md5(document.getElementById('password').value));

      // let tq_jx_token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZW5hbnRfaWQiOiIwMDAwMDAiLCJjb2RlIjoyMDAsInJvbGVfY29kZXMiOltdLCJ1c2VyX25hbWUiOiJobmFkbWluIiwiYXV0aG9yaXRpZXMiOlsiMTQwNzg3MjE1NzU4ODkxODMwMyJdLCJjbGllbnRfaWQiOiJ1c2VyY2VudGVyIiwicm9sZV9pZHMiOlsxNDA3ODcyMTU3NTg4OTE4MzAzXSwiYWRtaW5pc3RyYXRvciI6ZmFsc2UsImdyYW50X3R5cGUiOiJwYXNzd29yZCIsInVzZXJfaWQiOiIxNjUwNDM5MzMwNjk2NTMyMDA2Iiwib3JnX2lkIjoiMTM1NDYxNzY4NjI1NjAwMTAzNCIsInN1Y2Nlc3MiOnRydWUsInNjb3BlIjpbImFsbCJdLCJvYXV0aF9pZCI6IiIsImV4cCI6MTY4MjQ1NjU5MywianRpIjoiNWQ4OTVjMWYtOGE2OC00NGVhLTgwMDEtYWJlZmUzYjZiM2IxIn0.YEcrkK-ijr1kHMQW6FNM6k15Wo7QFX9SzvWVzwLcBG8';
      let tq_jx_token =  document.getElementById('jx_token').value;
      if(tq_jx_token){
        params.append('tq_jx_token', tq_jx_token);
      }
      
      axios.post(loginUrl, params, {
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
        // ,auth: {
        //   username: client_id,
        //   password: client_secret
        // }
      })
        .then(function (response) {
          debugger
          let data = response.data
          if(data.code===200){
            const token = response.data.data.token
            document.getElementById('token').value = token;
            let toPath = bizUrl + '&token='+token;
            // window.open(toPath,'_blank');
            var myiframe = document.getElementById("myiframe");
            myiframe.setAttribute("src", toPath);
          }else{
            document.getElementById('token').value = response.data.msg;
          }
         
        })
        .catch(function (error) {
          console.log(error);
          // 处理登录失败后的操作
        });
    }
  </script>
</head>
<body>
<h1>低代码平台 SSO Demo</h1>
<form>
  <label>用户名:</label>
  <input type="text" id="username">
  <label>密码:</label>
  <input type="password" id="password">
  <button type="button" onclick="login()">登录</button>
  <button type="button" onclick="goto()">跳转</button>
  <br>
  <label>基线token:</label>
  <textarea name="jx_token" id="jx_token"  cols="100" rows="2"></textarea>
  <br>
  <label>返回token:</label>
  <textarea name="token" id="token" disabled cols="100" rows="2"></textarea>
  <iframe id="myiframe" width="1600" height="600" src=""></iframe>
</form>
</body>
</html>
